package com.jumper.study.admin.service.impl;

import java.util.Collection;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.jumper.study.admin.service.LessonChapterService;
import com.jumper.study.db.dao.LessonChapterMapper;
import com.jumper.study.db.model.LessonChapter;

@Service
public class LessonChapterServiceImpl extends ServiceImpl<LessonChapterMapper, LessonChapter> implements LessonChapterService {

    @Override
    public List<LessonChapter> getByLessonId(Long id) {
        LambdaQueryWrapper<LessonChapter> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(LessonChapter::getLessonId, id);
        return getBaseMapper().selectList(wrapper);
    }

    @Override
    public boolean onselfById(Long id, boolean onself) {
        LambdaUpdateWrapper<LessonChapter> wrapper = Wrappers.lambdaUpdate();
        wrapper.set(LessonChapter::getOnself, onself);
        wrapper.eq(LessonChapter::getId, id);
        Integer ret = getBaseMapper().update(wrapper);
        return SqlHelper.retBool(ret);
    }

    @Override
    @Transactional
    public boolean onselfBatchById(Collection<Long> ids, boolean onself) {
        LambdaUpdateWrapper<LessonChapter> wrapper = Wrappers.lambdaUpdate();
        wrapper.set(LessonChapter::getOnself, onself);
        wrapper.in(LessonChapter::getId, ids);
        Integer ret = getBaseMapper().update(wrapper);
        return SqlHelper.retBool(ret);
    }

    @Override
    public boolean removeByLessonId(Long id) {
        LambdaQueryWrapper<LessonChapter> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(LessonChapter::getLessonId, id);
        Integer ret = getBaseMapper().delete(wrapper);
        return SqlHelper.retBool(ret);
    }
    
}
